<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.keywords" placeholder="关键字/id/会员id/会员手机号" style="width: 200px;" class="filter-item"
        @keyup.enter.native="handleFilter" />
      <el-select v-model="listQuery.status" placeholder="审核状态" clearable style="width: 150px" class="filter-item">
        <el-option label="待审核" :value="0" />
        <el-option label="通过" :value="1" />
        <el-option label="驳回" :value="2" />
        <!-- <el-option v-for="(a, i) in status" :key="i" :label="a" :value="i" /> -->
      </el-select>
      <!-- <datePicker class="filter-item" v-model="listQuery.date"></datePicker> -->
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
    </div>
    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="ID" prop="id" sortable="custom" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员id" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员名称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员手机号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收款方式" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.type == 1" style="color: blue;">支付宝</span>
          <span v-if="scope.row.type == 2" style="color: green;">微信</span>
          <span v-if="scope.row.type == 3" style="color: red;">银行卡</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0" style="color: blue;">待审核</span>
          <span v-if="scope.row.status == 1" style="color: green;">通过</span>
          <span v-if="scope.row.status == 2" style="color: red;">驳回</span>
        </template>
      </el-table-column>
      <el-table-column label="收款人姓名" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收款人账号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.acount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收款二维码" width="220" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.img">
            <img width="200px" @click="showImg(qiniuDomain + scope.row.img)" :src="qiniuDomain + scope.row.img" />
          </span>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="添加时间" align="center">
        <template slot-scope="{ row }">
          {{ _date(row.create_time) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <span v-permission="['/members/authEdit']">
            <el-button size="small" type="primary" @click="show(scope.row)">编辑</el-button>
          </span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <el-dialog title="编辑状态" :visible.sync="show_" width="300px">
      <el-select v-model="item.status">
        <el-option label="待审核" :value="0" />
        <el-option label="通过" :value="1" />
        <el-option label="驳回" :value="2" />
        <!-- <el-option v-for="(a, i) in status" :key="i" :label="a" :value="i" /> -->
      </el-select>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handle()">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="图片放大器" :visible.sync="showImg_">
      <img :src="img" width="100%" height="100%" />
    </el-dialog>
  </div>
</template>

<script>
  import {
    paymentList,
    paymentEdit
  } from '@/api/members';

  import waves from '@/directive/waves';
  import {
    parseTime
  } from '@/utils';
  import Pagination from '@/components/Pagination';
  import permission from '@/directive/permission/index.js';
  import {
    dateHandle
  } from '@/api/dateHandle';
  import datePicker from '@/components/Upload/datePicker';
  export default {
    components: {
      Pagination,
      datePicker,
    },
    directives: {
      waves,
      permission,

    },
    data() {
      return {
        tableKey: 0,
        list: null,
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 10,
          date: []
        },
        showImg_: false,
        img: null,
        show_: false,
        item: {},
        status: {
          0: '待审核',
          1: '通过',
          2: '驳回'
        }
      };
    },
    created() {
      this.getList()
    },
    methods: {
      _date(t) {
        return dateHandle('Y-m-d H:i:s', t);
      },
      getList() {
        this.listLoading = true;
        paymentList(this.listQuery).then(res => {
          this.list = res.data.data;
          this.total = res.data.total;
          setTimeout(() => {
            this.listLoading = false;
          }, 0.3 * 1000);
        });
      },
      handle() {
        paymentEdit({
          id: this.item.id,
          'status': this.item.status
        }).then(res => {
          if (res.code == 20000) {
            this.$message({
              type: 'success',
              message: res.msg
            });
            this.show_ = false;
            this.getList()
          }
        })
      },
      show(item) {
        this.show_ = true
        this.item = item
        console.log(this.item);
      },
      showImg(img) {
        this.showImg_ = true
        this.img = img
      }
    }
  };
</script>
